package com.eqdd.yiqidian.ui.mine.setting;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.eqdd.yiqidian.FeedBackInfoActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.adapter.GridSpacingItemDecoration;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.FeedBackListResultBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.ui.mine.renwu.TextActivity;
import com.eqdd.yiqidian.ui.select.RichTextResult;
import com.eqdd.yiqidian.ui.select.ShowRichTextActivity;
import com.eqdd.yiqidian.utils.PicUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.eqdd.yiqidian.widget.UniversalImageLoader;
import com.hitomi.tilibrary.style.index.NumberIndexIndicator;
import com.hitomi.tilibrary.style.progress.ProgressPieIndicator;
import com.hitomi.tilibrary.transfer.TransferConfig;
import com.hitomi.tilibrary.transfer.Transferee;
import com.luck.picture.lib.entity.LocalMedia;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.rong.imkit.RongIM;
import io.rong.imkit.userInfoCache.RongUserInfoManager;
import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.PublicServiceProfile;
import io.rong.imlib.model.PublicServiceProfileList;
import io.rong.imlib.model.SearchConversationResult;
import io.rong.imlib.model.UserInfo;

/**
 * Created by 吕志豪 on 17-10-11  下午2:47.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class FeedBackInfoActivity extends BaseActivity {


    private FeedBackInfoActivityCustom dataBinding;
    private FeedBackListResultBean FeedBackListResultBean;
    private Transferee transferee;
    private MaterialDialog saveDialog;
    private TransferConfig config;


    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_feedback_info);
    }

    @Override
    public void initData() {

        Intent intent = getIntent();
        initTopTitleBar(View.VISIBLE, "反馈详情");
        FeedBackListResultBean = (FeedBackListResultBean) intent.getSerializableExtra(Config.FEEDBACK_INFO);
        transferee = Transferee.getDefault(this);
        config = TransferConfig.build()
                .setMissPlaceHolder(R.mipmap.ic_launcher)
                .setErrorPlaceHolder(R.mipmap.ic_launcher)
                .setProgressIndicator(new ProgressPieIndicator())
                .setIndexIndicator(new NumberIndexIndicator())
                .setJustLoadHitImage(true)
                .setOnLongClcikListener((imageView, i) -> {
                    ArrayList<Object> objects = new ArrayList<>();
                    objects.add("保存图片");
                    SlimAdapterEx slimAdapterEx = SlimAdapterEx.create().registerDefault(R.layout.list_item_63, new SlimInjector() {
                        @Override
                        public void onInject(Object data, IViewInjector injector) {

                            injector.text(R.id.tv_content, (String) data)
                                    .clicked(R.id.tv_content, v -> {
                                        saveDialog.dismiss();
                                        saveImageByUniversal(imageView);
                                    });
                        }
                    }).updateData(objects);
                    saveDialog = new MaterialDialog.Builder(this)
                            .adapter(slimAdapterEx, new LinearLayoutManager(this))
                            .build();
                    saveDialog.show();
                })
                .setImageLoader(UniversalImageLoader.with(getApplicationContext()))
                .create();
        if (FeedBackListResultBean.getStatus() == 0) {
            dataBinding.etContent.setVisibility(View.GONE);
            dataBinding.tvReplay.setVisibility(View.GONE);

        } else {
            dataBinding.etContent.setVisibility(View.GONE);
            dataBinding.tvReplay.setVisibility(View.VISIBLE);
            dataBinding.tvReplay.setText("客服回复:\n" +
                    "        " + FeedBackListResultBean.getDealMessage());
        }
    }

    @Override
    public void setView() {
        dataBinding.tvTitle.setText(FeedBackListResultBean.getFbackTitle());
        dataBinding.tvType.setText(FeedBackListResultBean.getFbackType() + "");
        dataBinding.tvContent.setText(FeedBackListResultBean.getFbcontent());
        dataBinding.recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        dataBinding.recyclerView.addItemDecoration(new GridSpacingItemDecoration(3, 10, false));
        List<ImageView> imageViews = new ArrayList<>(FeedBackListResultBean.getPicAddress() == null ? 0 : FeedBackListResultBean.getPicAddress().size());
        SlimAdapterEx.create().registerDefault(R.layout.list_item_64, new SlimInjector() {
            @Override
            public void onInject(Object data, IViewInjector injector) {
                imageViews.add(FeedBackListResultBean.getPicAddress().indexOf(data), (ImageView) injector.findViewById(R.id.iv_img));
                injector.image(R.id.iv_img, data)
                        .clicked(R.id.iv_img, v -> {

                            config.setNowThumbnailIndex(0);
                            config.setSourceImageList(FeedBackListResultBean.getPicAddress());
                            config.setOriginImageList(imageViews);
                            transferee.apply(config).show();
                        });
            }
        }).attachTo(dataBinding.recyclerView).updateData(FeedBackListResultBean.getPicAddress());
    }

}
